package com.ruoyi.web.controller.charge;

import com.ruoyi.charge.domain.ChargeCharge;
import com.ruoyi.charge.domain.vo.DoctorPatientDrugVo;
import com.ruoyi.charge.domain.vo.DoctorRegisterVo;
import com.ruoyi.charge.service.IChargeChargeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/collect/charge")
public class ChargeChargeController extends BaseController {
    @Autowired
    private IChargeChargeService chargeChargeService;

       @PreAuthorize("@ss.hasPermi('system:charge:list')")
    @GetMapping("/list")
    public AjaxResult getInfo (Long registeredId)
    {
        startPage();
        ChargeCharge chargeCharge = chargeChargeService.selectCharge(registeredId);
        return success(chargeCharge);
    }

    @PreAuthorize("@ss.hasPermi('system:charge:list')")
    @GetMapping("/registerList")
    public AjaxResult getInfos (Long RegisterId)
    {
        startPage();
        DoctorRegisterVo doctorRegisterVo = chargeChargeService.selectDoctorRegisterVoById(RegisterId);
        return success(doctorRegisterVo);
    }

    @PreAuthorize("@ss.hasPermi('system:charge:list')")
    @GetMapping("/listDoctorRegister")
    public TableDataInfo list (Long RegisterId)
    {
        startPage();
        List<DoctorPatientDrugVo> drugsDurgs = chargeChargeService.selectDrugsDurgList(RegisterId);
        return getDataTable(drugsDurgs);
    }
    /**
     * 现金支付
     */
    @PreAuthorize("@ss.hasPermi('system:durg:remove')")
    @Log(title = "现金", businessType = BusinessType.DELETE)
    @GetMapping("/{id}/{patientId}")
    public AjaxResult remove(@PathVariable Long[] id, @PathVariable Long patientId) {
        System.out.println(Arrays.toString(id));
        System.out.println(patientId);
        for (Long physicId : id) {
            chargeChargeService.updatePayStatusById(physicId, patientId);
        }
        return success();
    }

}
